from langchain_community.document_loaders.csv_loader import CSVLoader
from langchain.text_splitter import RecursiveCharacterTextSplitter
from langchain_community.vectorstores import FAISS
from langchain_community.embeddings import OllamaEmbeddings
from langchain_core.prompts import ChatPromptTemplate
from langdev_helper.llm.qwen import llm
from langchain_core.prompts import PromptTemplate
from langdev_core.llms.qianfan import call_llm

loader = CSVLoader(file_path='../../testdata/ordersample.csv')
data = loader.load()

text_splitter = RecursiveCharacterTextSplitter(
    chunk_size=1000, chunk_overlap=200, add_start_index=True
)
all_splits = text_splitter.split_documents(data)

csv_content = ""
for doc in all_splits:
    # print(doc.page_content)
    csv_content += "\n"
    csv_content += doc.page_content
    csv_content += "\n"

# print(csv_content)

rag_prompt="""仅根据所提供的上下文回答以下问题:

<context>
{context}
</context>

问题: {question}"""


prompt_template = PromptTemplate.from_template(rag_prompt)

q = "订单ID是123453的收货人是谁，电话是多少?"
prompt_user = prompt_template.format(context=csv_content, question=q)
# print(prompt_user)

print(q)
res = call_llm(prompt_user)

print(res)
